﻿using VideoServices.Domain.Entities;
using VideoServices.Services.Dto;
using VideoServices.Services.Translation.Base;

namespace VideoServices.Services.Translation
{
    public class StockTranslator : BaseTranslator
    {
        #region Overrides of BaseTranslator

        /// <summary>
        /// Translates to concrete entity.
        /// </summary>
        /// <typeparam name="TDto">The type of the dto.</typeparam>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="dto">The dto.</param>
        /// <param name="concreteEntity">The concrete entity.</param>
        /// <returns></returns>
        public override TEntity TranslateToConcreteEntity<TDto, TEntity>(TDto dto, TEntity concreteEntity)
        {
            StockDto tempDto = dto as StockDto;
            if (tempDto != null)
            {
                Stock tempEntity = concreteEntity as Stock;
                if (tempEntity != null)
                {
                    tempEntity.id = tempDto.Id;
                    tempEntity.holding = tempDto.Holding;
                    tempEntity.catalogue_id = tempDto.CatalogueId;
                    tempEntity.warehouse_id = tempDto.WarehouseId;
                    return tempEntity as TEntity;
                }
            }
            return default(TEntity);
        }

        /// <summary>
        /// Translates to concrete dto.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <typeparam name="TDto">The type of the dto.</typeparam>
        /// <param name="entity">The entity.</param>
        /// <param name="concreteDto">The concrete dto.</param>
        /// <returns></returns>
        public override TDto TranslateToConcreteDto<TEntity, TDto>(TEntity entity, TDto concreteDto)
        {
            Stock tempEntity = entity as Stock;
            if (tempEntity != null)
            {
                StockDto tempDto = concreteDto as StockDto;
                if (tempDto != null)
                {
                    tempDto.Id = tempEntity.id;
                    tempDto.Holding = tempEntity.holding;
                    tempDto.CatalogueId = tempEntity.catalogue_id;
                    tempDto.WarehouseId = tempEntity.warehouse_id;
                    return tempDto as TDto;
                }
            }
            return default(TDto);
        }

        #endregion
    }
}